package me.vudu.Conflict.Runnables;

import me.vudu.Conflict.ConflictPlugin;


import org.getspout.spoutapi.player.SpoutPlayer;

/**
 * triggert automatisches Hungern
 * @author vwendel
 *
 */
public class HungerUpdateRunnable implements Runnable{
	
	@Override
	public void run() {
		  for(SpoutPlayer p: ConflictPlugin.players){
	    	   int diff=0;
	    	   if(ConflictPlugin.playerIsInTeam(p).equals("blue")){
	    		   diff = ConflictPlugin.getArtBlue()[0]-ConflictPlugin.getArtRed()[0];
	    	   }else{
	    		   diff = ConflictPlugin.getArtRed()[0]-ConflictPlugin.getArtBlue()[0];
	    	   }
	    	   
	    	   
	    	   
	    	   diff = Math.max(diff,-1); //maximales penalty von 1
	    	   
	    	   	    	   
	    	   diff = ConflictPlugin.hungerPerTime-diff;
	    	   diff = Math.max(diff, 1); //immer mind. 1 Hunger
	    	   
	    	   
	    	   //Wenn keine basis gebaut -> verdoppeln
	    	   if(ConflictPlugin.playerIsInTeam(p).equals("blue")){
	    		   if(null==ConflictPlugin.blueBase){
	    			   diff = diff*2;
	    		   }
	    	   }
	    	   if(ConflictPlugin.playerIsInTeam(p).equals("red")){
	    		   if(null==ConflictPlugin.redBase){
	    			   diff = diff*2;
	    		   }
	    	   }
	    	   
    		   p.setFoodLevel(p.getFoodLevel()-(diff));
    		   
	       }
	}

}
